<body>
<h1>添加学生</h1>
<form action="insert.php" method="post">
    <table>
        <tr>
            <td>姓名：</td>
            <td><input type="text" name="name" require/></td>
        </tr>
        <tr>
            <td>年龄：</td>
            <td><input type="number" name="age" require/></td>
        </tr>
        <tr>
            <td>成绩：</td>
            <td><input type="text" name="score" require/></td>
        </tr>
        <tr>
            <td><button type="submit" name="submit">添加</button></td>
        </tr>
    </table>
</form>
</body>
</html>

<?php
require('conn.php');
session_start();
if(!$_SESSION['user.account']){
    //print_r($_SESSION['user.account']);
    header('location:login.php');
}
@$name=$_POST['name'];
@$age=$_POST['age'];
@$score=$_POST['score'];

$sql="insert into result (name,age,result) values('$name','$age','$score') ";
//echo $sql;
if(isset($_POST["submit"])):
    $r=mysqli_query($conn,$sql);
    if($r){
        header("location:index.php");
    }else{
        echo "添加失败";
    }
endif;

